<!DOCTYPE html>
<html class="ui-page-login">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>用户登陆</title>
    <!--<link href="css/mui.min.css" rel="stylesheet" />-->
    <!--<link href="css/style.css" rel="stylesheet" />-->
    <link href="css/login.css" rel="stylesheet" />
    <style>

    </style>

</head>

<body>
<div id="app">
    <div class="app-container">
        <div class="view-container">
            <div class="form-container">
                <div class="logo-container"><i class="logo"></i><span class="logo-desc">缤纷福利&nbsp;精彩纷呈</span></div>
                <ul class="login-form">
                    <li>
                        <input type="text" id="phoneNum" value="" placeholder="请输入手机号">
                        <button class="vcode-btn" id="codeBtn">获取验证码</button>
                    </li>
                    <li><input type="text" id="smsCode" value="" placeholder="请输入验证码"></li>

                </ul>
                <button class="btn-lg" onclick="getlogin()">登&nbsp;录</button>

            </div>
        </div>
    </div>
</div>

<script src="js/mui.min.js"></script>
<script src="js/mui.enterfocus.js"></script>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script src="js/app.js"></script>
<script src="js/common.js"></script>
<script src="https://cdn.bootcss.com/layer/3.0.1/layer.min.js"></script>
<script type="application/javascript">
    var countdown;
    function settime(me,tm) {
        if (countdown == 0) {
            $(me).removeAttr("disabled");
            $(me).text("获取验证码");
            $(me).removeClass("grey");
            countdown = 60;
            window.sessionStorage.setItem("countdown","0");
            clearInterval(tm);
        } else {
            $(me).attr("disabled","disabled");
            $(me).addClass("grey");
            $(me).text(countdown+" s");
            countdown--;
            window.sessionStorage.setItem("countdown",countdown+"");
        }

    }
    $("#codeBtn").click(function(){
        //检查手机号是否合法
        var phoneNum = $("#phoneNum").val();
        if(!Common.isPhoneNumber(phoneNum)){
            layer.msg("请输入正确的手机号！");
            return;
        }
        //后台请求验证码
        var paramStr = {};
        paramStr.phoneNum =phoneNum;
        var params = {};
        params.paramStr = JSON.stringify(paramStr);

        Common.ajaxWithParam("/fenful/api/v1/sms/loginSms", params, function(data) {
            layer.msg("验证码发送成功！");
            var time = setInterval(function() {
                settime($("#codeBtn"),time)
            },1000);
        });

    });


    function getlogin(){

        var invitePhoneNum = Common.queryGetParam("invitePhoneNum");
        //检查手机号是否合法
        var phoneNum = $("#phoneNum").val();
        if(!Common.isPhoneNumber(phoneNum)){
            layer.msg("请输入正确的手机号！");
            return;
        }
        var smsCode = $("#smsCode").val();
        if(!smsCode){
            layer.msg("请输入验证码！");
            return;
        }
        var paramStr = {};
        paramStr.phoneNum = phoneNum;
        paramStr.verifyCode = smsCode;
        if(invitePhoneNum){
            window.localStorage.setItem("invitePhoneNum", invitePhoneNum);
            //paramStr.invitePhoneNum = invitePhoneNum;
        }

        var params = {};
        params.paramStr = JSON.stringify(paramStr);
        Common.ajaxWithParam("/fenful/api/v1/login/phoneVerifyLogin", params, function(data) {
            window.localStorage.setItem("phoneNum", phoneNum);
            window.localStorage.setItem("token", data.token);
            //需要回跳的页面
            var _path = Common.queryGetParam("_path");
            if(!_path){
                _path = window.localStorage.getItem("_path");
            }
            if(_path){
                if(_path.indexOf("?")==0){
                    window.location.href=_path+"?invitePhoneNum="+invitePhoneNum;
                }else if(_path.indexOf(invitePhoneNum)==0){
                    window.location.href=_path+"&invitePhoneNum="+invitePhoneNum;
                }else{
                    window.location.href=_path;
                }

            }else{
                layer.msg("登录成功");
            }

        });
    }
    $(function () {
        countdown =parseInt(window.sessionStorage.getItem("countdown"))||0;
        var time = setInterval(function() {
            settime($("#codeBtn"),time)
        },1000);
    });
</script>
</body>

</html>